﻿using System;
using System.Collections.Generic;
using System.Text;

namespace PCR.Logic
{
    using PCR.Base;
    using System.Diagnostics;

    /// <summary>
    /// Patients' reports manager, contains all the operation of the patients' reports
    /// </summary>
    internal class PatientManager : IPatientManager
    {
        IDatabase _database = null;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="database">Database interface<param>
        public PatientManager(IDatabase database)
        {
            System.Diagnostics.Debug.Assert(database != null);
            this._database = database;
        }

        /// <summary>
        /// Add a new patient report, should be a new instance
        /// </summary>
        /// <param name="item">Patient report instance to add<param>
        public void Add(IPatientReport item)
        {
            Debug.Assert(item != null);
            this._database.PatientReports.Append(item);
        }

        /// <summary>
        /// Add new patient report list, should be new instances
        /// </summary>
        /// <param name="items">Patient report list to add<param>
        public void Add(IList<IPatientReport> items)
        {
            Debug.Assert(items != null);
            this._database.PatientReports.Append(items);
        }

        /// <summary>
        /// Remove the specified patient report instance
        /// </summary>
        /// <param name="item">Patient report to remove<param>
        public void Remove(IPatientReport item)
        {
            Debug.Assert(item != null);
            this._database.PatientReports.Delete(item);
        }

        /// <summary>
        /// Remove patient report by object ID
        /// </summary>
        /// <param name="id">Patient report object ID<param>
        public void RemoveByID(Guid id)
        {
            this._database.PatientReports.DeleteByID(id);
        }

        /// <summary>
        /// Remove all the patient reports
        /// </summary>
        public void RemoveAll()
        {
            this._database.PatientReports.DeleteAll();
        }

        /// <summary>
        /// Modify the patient report
        /// </summary>
        /// <param name="item">Patient report instance to modify<param>
        public void Modify(IPatientReport item)
        {
            Debug.Assert(item != null);
            this._database.PatientReports.Update(item);
        }

        /// <summary>
        /// Modify the patient report by object ID
        /// </summary>
        /// <param name="id">Patient report object ID<param>
        /// <param name="item">Patient report instance to modify<param>
        public void Modify(Guid id, IPatientReport item)
        {
            Debug.Assert(item != null);
            this._database.PatientReports.UpdateByID(id, item);
        }

        /// <summary>
        /// Get the patient report by object ID
        /// </summary>
        /// <param name="id">Patient report object ID to find<param>
        public IPatientReport GetByID(Guid id)
        {
            return this._database.PatientReports.SelectByID(id);
        }

        /// <summary>
        /// Get all the patient report list
        /// </summary>
        public IList<IPatientReport> List 
        {
            get
            {
                return this._database.PatientReports.SelectAll();
            }
        }

        /// <summary>
        /// Search the patient report by search filter
        /// </summary>
        /// <param name="filter">Search filter<param>
        public IList<IPatientReport> Search(ISearchFilter<IPatientReport> filter)
        {
            return this._database.PatientReports.Search(filter);
        }
    }
}
